﻿using System;
using System.Collections.Generic;

namespace ApplicationGenerator.Lists.BusinessLogic
{
    [Serializable]
    public class HQLListType : IConfigDetails
    {
        IList<Column> _columns;
        IList<FilterColumn> _filteredColumns;
        IList<ConfiguredColumn> _configuredColumns;
        string _primaryKeyName;
        string _hqlQuerry;

        #region IListType Members

        public IList<Column> AvailableColumns
        {
            get
            {
                return _columns;
            }
            set
            {
                _columns = value;
            }
        }

        public string PrimaryKeyName
        {
            get
            {
                return _primaryKeyName;
            }
            set
            {
                _primaryKeyName = value;
            }
        }

        public string HQLQuerry
        {
            get { return _hqlQuerry; }
            set { _hqlQuerry = value; }
        }

        public string CreateHqlQuerry()
        {
            return _hqlQuerry;
        }

        public IList<FilterColumn> FilteredColumns
        {
            get
            {
                return _filteredColumns;
            }
            set
            {
                _filteredColumns = value;
            }
        }

        public IList<ConfiguredColumn> ConfiguredColumns
        {
            get
            {
                return _configuredColumns;
            }
            set
            {
                _configuredColumns = value;
            }
        }

        public ConfiguredColumn GetPrimaryKeyColumn()
        {
            foreach (var configuredColumn in _configuredColumns)
            {
                if (_primaryKeyName == configuredColumn.Column.Name)
                {
                    return configuredColumn;
                }
            }

            throw new Exception("Kolumna z id elementu musi być wyświetlana na liście");
        }

        #endregion
    }
}
